package in.iqing.model.sp;

import android.content.Context;
import android.content.SharedPreferences;

import in.iqing.App;

/**
 * Created by ZuoShu on 15/7/3.
 */
public class ApiSP {
    private static SharedPreferences apiSp;
    private static final boolean USE_TEST_SERVER = false;

    private static SharedPreferences getSharedPreference() {
        if (apiSp == null) {
            apiSp = App.getInstance().getSharedPreferences("api", Context.MODE_PRIVATE);
        }
        return apiSp;
    }

    public static void clear() {
        getSharedPreference().edit().clear().apply();
    }

    public static String getRoot() {
        if (USE_TEST_SERVER) {
            return getSharedPreference().getString("root", "http://bog.iqing.in");
        } else {
            return getSharedPreference().getString("root", "https://api.iqing.in");
        }
    }

    public static void setRoot(String root) {
        getSharedPreference().edit().putString("root", root).apply();
    }

    public static String getBook() {
        return getSharedPreference().getString("book", getRoot() + "/book");
    }

    public static void setBook(String book) {
        getSharedPreference().edit().putString("book", book).apply();
    }

    public static String getRecommend() {
        return getSharedPreference().getString("recommend", getRoot() + "/recommend/");
    }

    public static void setRecommend(String recommend) {
        getSharedPreference().edit().putString("recommend", recommend).apply();
    }

    public static String getCategory() {
        return getSharedPreference().getString("category", getRoot() + "/category");
    }

    public static void setCategory(String category) {
        getSharedPreference().edit().putString("category", category).apply();
    }

    public static String getVolume() {
        return getSharedPreference().getString("volume", getRoot() + "/volume");
    }

    public static void setVolume(String volume) {
        getSharedPreference().edit().putString("volume", volume).apply();
    }

    public static String getChapter() {
        return getSharedPreference().getString("chapter", getRoot() + "/chapter");
    }

    public static void setChapter(String chapter) {
        getSharedPreference().edit().putString("chapter", chapter).apply();
    }

    public static String getContent() {
        return getSharedPreference().getString("content", getRoot() + "/content");
    }

    public static void setContent(String content) {
        getSharedPreference().edit().putString("content", content).apply();
    }

    public static String getLogin() {
        return getSharedPreference().getString("login", getRoot() + "/login/");
    }

    public static String getSms() {
        return getSharedPreference().getString("sms", getRoot() + "/sms/");
    }

    public static String getRegister() {
        return getSharedPreference().getString("register", getRoot() + "/register/");
    }

    public static String getAuthor(){
        return getSharedPreference().getString("author", getRoot() + "/author");
    }

    public static String getPress(){
        return getSharedPreference().getString("press", getRoot() + "/press");
    }

    public static String getSearch(){
        return getSharedPreference().getString("search", getBook() + "/search/");
    }

    public static String getLatestUpdate(){
        return getSharedPreference().getString("latest", getBook() + "/last/");
    }

}
